from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import render, redirect
class M1(MiddlewareMixin):
    """中间件"""

    def process_request(self, request):
        #排除不需要登录就能访问的页面
        if request.path_info == '/login/':

            return 

        #1.读取当前访问用户的session信息,如果能读到说明已经登录过可以继续向后走
        info_dict = request.session.get('info')
        if info_dict:
            return


        return redirect('/login/')